<!--
 * @Descripttion: |
 * @version: 1.0
 * @Author: 王娆
 * @Date: 2020-09-02 20:21:14
 * @LastEditors: 王娆
 * @LastEditTime: 2020-09-04 14:23:37
-->
<template>
  <div class="login">
    <header>登录</header>
    <main>
      <!-- 登录表单部分 -->
      <van-form @submit="onSubmit">
        <van-field v-model="loginForm.username" name="用户名" label="用户名" placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]" />
        <van-field v-model="loginForm.password" type="password" name="密码" label="密码" placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]" />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">登录</van-button>
        </div>
        <div class="as">
          <a @click="()=>{this.$router.push('/register')}">新用户注册</a>
          <a>忘记密码</a>
        </div>
      </van-form>
    </main>
    <footer></footer>
  </div>
</template>

<script>
import { loginUrl } from "../../api/user";
export default {
  data () {
    return {
      loginForm: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    async onSubmit () {
      let data = await loginUrl(this.loginForm);
      console.log(data)
      if (data.code === 200) {
        this.$router.push('/homeIndex/home')
        this.$toast.success('登陆成功');
      }
    }
  },
};
</script>

<style lang='scss' scoped>
header {
  background: #1989fa;
  width: 100%;
  height: 48px;
  line-height: 48px;
  text-align: center;
  color: #fff;
  font-size: 22px;
}
main {
  padding: 0 20px;
  .van-form {
    margin-top: 20px;
    .van-field {
      margin-bottom: 10px;
    }
  }
  .as {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    a {
      font-size: 14px;
      color: #1989fa;
    }
  }
}
</style>